﻿using System;
using System.Collections.Specialized;
using System.Configuration;

namespace CProcess.Services
{
    public class Settings
    {
        private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        private readonly NameValueCollection _configuration = null;        

        public Settings(string sectionName)
        {
            try
            {
                _configuration = (NameValueCollection)ConfigurationManager.GetSection(sectionName);                
            }
            catch(Exception e)
            {
                log.Fatal(e.Message);
                log.Fatal(e);
            }
        }

        /// <summary>
        /// Get value from a specific section in configuration given the key/name
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public string GetValue(string name)
        {
            return _configuration != null ? _configuration[name] : String.Empty;
        }
    }
}
